package inner;

import com.sun.glass.ui.Size;

//内部类 -- 实例内部类/非静态内部类，静态内部类，局部内部类，匿名内部类
class OuterClass {
    public int data1 =1 ;
    public int data2 = 2;
    public static int data3 = 3;
    public void test(){
        System.out.println("OuterClass::test()");
    }
    /**
    *实例内部类
     * 1，如何获取实例内部类的对象 -- OuterClass.InnerClass i = o.new InnerClass();
     * 2，实现内部类当中，不能有静态的成员变量,如果非要定义，用final修饰 -- public static final int data6 = 6
     * 3,就要在实例内部类中访问外部类相同的成员变量 -- System.out.println(OuterClass.this.data1);
    */
    class InnerClass {
        int data1 = 111;
        public int data4 = 4;
        int data5 = 5;
        //public static int data6; error static的优先级高于InnerClass
        public static final int data6 = 6; //final是常量的意思

        public void func(){
            System.out.println("InnerClass::func()");
            /*OuterClass o1 = new OuterClass();
            System.out.println(o1.data1);*/
            System.out.println(data1);//打印111，就近原则
            System.out.println(OuterClass.this.data1);//在实例内部类中拿到外部类的this
            System.out.println(data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
        }

        public void test(){
            //static final int c = 0;
            System.out.println("OutClass::test()");
            final int SIZE= 20; //常量是在程序编译的时候就已经确定了，通常定义成大写，只能初始化一次，不能修改
            //SIZE = 10;
        }
    }
}

public class test {
    public static void main1(String[] args) {
        OuterClass o = new OuterClass();
        System.out.println(o.data1);
        //InnerClass i =new innerClass(); error

        //前面拿到类型，后面从对象中new一个东西
        OuterClass.InnerClass i = o.new InnerClass();
        OuterClass.InnerClass i2 = new OuterClass().new InnerClass();
        System.out.println(i.data4);
        i2.func();
    }

    public static void main(String[] args) {
        OuterClass o = new OuterClass();
        OuterClass.InnerClass i = o.new InnerClass();
        i.func();
    }
}
